package client // Package client import "xemo.top/docker/docker/client"
import (
	"context"
	"net/url"
	"time"
	timetypes "xemo.top/docker/docker/api/types/time"
)

// ContainerRestart 停止并再次启动容器。它使守护进程在给定超时的情况下等待容器再次启动特定的时间
// ContainerRestart stops and starts a container again.It makes the daemon to wait for the container to be up again for a specific amount of time ,given the timeout
func (cli *Client) ContainerRestart(ctx context.Context, containerID string, timeout *time.Duration) error {
	query := url.Values{}
	if timeout != nil {
		query.Set("t", timetypes.DurationToSecondsString(*timeout))
	}
	resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
	defer ensureReaderClosed(resp)
	return err
}
